package com.itheima.charset;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {

        //ASCII字符集：只有英文、数字、符号等，占1个字节
        //GBK字符集：汉字占2个字节，英文、数字占1个字节
        //UTF-8字符集：汉字占3个字节，英文、数字占1个字节

        //字符的编码和解码
        String s1 = "你好abc666";
        //byte[] bytes = str.getBytes();      //平台默认的UTF-8编码
        byte[] bytes = s1.getBytes("GBK");     //指定GBK编码
        System.out.println(bytes.length);
        System.out.println(Arrays.toString(bytes));

        //String s2 = new String(bytes);      //平台默认的UTF-8解码
        String s2 = new String(bytes,"GBK");        //指定GBK解码
        System.out.println(s2);

    }
}
